package com.happycat.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.happycat.Pagination;
import com.happycat.ResponseHeaderModel;
import com.happycat.ResponseModel;
import com.happycat.mobile.model.UserAccount;
import com.happycat.mobile.service.UserAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liaoyong
 * @since 2020-07-23
 */
@RestController
@RequestMapping("/userAccount")
@Api(value = "用户注册的账号", description = "用户注册的账号接口")
public class UserAccountController {
    @Autowired
	private UserAccountService userAccountService;
	
	@ApiOperation(value = "用户注册的账号详情")
    @RequestMapping(method = RequestMethod.POST, value = "/detail")
	public ResponseModel<UserAccount> detail(@RequestBody UserAccount userAccount){
		return userAccountService.selectOne(userAccount);
	}
	
	@RequestMapping(method = RequestMethod.POST, value = "/page")
	@ApiOperation(value = "用户注册的账号分页列表")
	public ResponseModel<Page<UserAccount>> Page(@RequestBody Pagination<UserAccount>page){
		if(page.getSize() * page.getCurrent() <= 50) {
			
			if(1 == page.getEntity().getType() ) {
				page.setDesc("nick");
			}else if(2 == page.getEntity().getType() ) {
				page.setDesc("account_name");
			}else if(3 == page.getEntity().getType() ) {
				page.setDesc("phone");
			}
		}else {
			if(1 == page.getEntity().getType() ) {
				page.setDesc("create_time");
			}
			if(2 == page.getEntity().getType() ) {
				page.setDesc("order_number_total","order_amount_total","focus_number_total");
			}
			if(3 == page.getEntity().getType() ) {
				page.setDesc("order_score_total","","");
			}
		}
		page.setDesc("order_number_total","focus_number_total","order_amount_total");
		return userAccountService.pageList(page);
	}
	
	@RequestMapping(method = RequestMethod.POST, value = "/add")
	@ApiOperation(value = "用户注册的账号新增")
	public ResponseHeaderModel add(@RequestBody UserAccount userAccount){
	
	   return userAccountService.add(userAccount);
	}

	@ApiOperation(value = "用户个人资料编辑")
	@RequestMapping(method = RequestMethod.POST, value = "/modify")
	public ResponseHeaderModel modify(@RequestBody UserAccount userAccount){	
	   return userAccountService.modify(userAccount);
	}

}

